﻿
Imports std

Public Class value_defination
    Inherits sentence

    Protected Friend Shared Shadows Function _isMeaningfulMark(ByVal c As Char) As Boolean
        Return False
    End Function

    Private variable As variable = Nothing
    Private name As String = Nothing

    Private Sub New(ByVal ivariable As variable, ByVal iname As String)
        'do not copy, these objects are all newly generated.
        variable = ivariable
        name = iname
    End Sub

    'do we need to nest? as simple, do not support now
    Protected Overrides Function invokeImpl(ByVal ctx As context) As Boolean
        assert(Not ctx Is Nothing, "ctx is nothing.")
        Dim o As Object = Nothing
        If variable.invoke(o) Then
            ctx.insertVariable(name, New bare_variable(variable, o))
            Return True
        Else
            Return False
        End If
    End Function

    Protected Shared Function parseImpl(ByVal input As String, ByRef index As Int64, _
                                        ByRef output As value_defination) As Boolean
        Dim v As variable = Nothing
        If variable.parse(input, index, v) Then
            Dim name As String = Nothing
            If value_name_defination.parse(input, index, name) Then
                output = New value_defination(v, name)
                Return True
            Else
                Return False
            End If
        Else
            Return False
        End If
    End Function

    Public Shared Shadows Function parse(ByVal input As String, ByRef index As Int64, _
                                         ByRef output As value_defination) As Boolean
        Return parsebase(input, index, output, AddressOf parseImpl)
    End Function
End Class
